﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DalatCooking.Core;
using DalatCooking.Core.Helper;
public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*
        if (!IsPostBack)
        {
            Label1.Text = DalatCooking.Core.Helper.MyEncode.Encode("123456");
            Label1.Text += "</br>"+ DalatCooking.Core.Helper.MyEncode.EncodeMD5("123456");
            Label1.Text += "</br>" + DalatCooking.Core.Helper.MyEncode.EncodeSHA1("123456");
            Label1.Text += "</br>" + DalatCooking.Core.Helper.MyEncode.EncodeSHA256("123456");
            Label1.Text += "</br>" + DalatCooking.Core.Helper.MyEncode.EncodeSHA384("123456");
            Label1.Text += "</br>"+DalatCooking.Core.Helper.MyEncode.EncodeSHA512("123456");
        }
         * */
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        Person u = PersonManager.Login(txtUserName.Text, txtPassword.Text);
        if (u != null)
        {
            Session.SetPersonLogged(u);
            Label1.Text = u.UserName;
          //  Response.Redirect(Request.Url.AbsoluteUri);
        }
        else
        {
            Session.Abandon();
            Label1.Text = "Error";
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Person u = Session.GetPersonLogged();
        bool rs = SecurityServices.HasPermission("Add", u.PersonId, SecurityServices.TypeAudit.Edit);
        if (rs == false)
            Label1.Text = "Ban khong co quyen thuc hien chuc nang nay";
        else
        {
            Label1.Text = "OK";
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Person u = Session.GetPersonLogged();
        bool rs = SecurityServices.HasPermission("Add", u.PersonId, SecurityServices.TypeAudit.Delete);
        if (rs == false)
            Label1.Text = "Ban khong co quyen thuc hien chuc nang nay";
        else
        {
            Label1.Text = "Ban co the thuc hien chuc nang nay";
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Person u = new Person();       
        u.Email = "admin@email.com";
        u.Password = "concho";
        if (PersonManager.ResetPassword(u))
        {
            Label1.Text = "OK";
        }
    }
}